import { AnimationClip } from 'cc'
import { initAnimation } from '../Utils'
import { DataCenter } from '../Runtime/DataCenter'

export class State {
  private _animationManager: ReturnType<typeof initAnimation> = null
  constructor(
    private animationComponent,
    private path: string,
    speed: number = 1 / 8,
    private wrapMode: AnimationClip.WrapMode = AnimationClip.WrapMode.Normal,
  ) {
    this._animationManager = initAnimation(this.animationComponent, DataCenter.getSpriteFramesByPath(this.path), speed)
  }
  get animationManager() {
    return this._animationManager
  }
  run() {
    this.runAnimation(this.wrapMode)
  }
  runAnimation(WrapMode?: AnimationClip.WrapMode) {
    this.animationManager.play(WrapMode || this.wrapMode)
  }
}
